package com.sychip.fhc.app.drawer.screen

import android.annotation.SuppressLint
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.BluetoothSearching
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Remove
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Slider
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.drawscope.inset
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.fhc.base.showSnackbar
import com.fhc.view.dialog.PopupSample
import com.fhc.view.zoom.rememberZoomState
import com.fhc.view.zoom.zoomable
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.sychip.fhc.app.todo.R
import com.sychip.fhc.lib.base.DecimalFormatter
import com.sychip.fhc.lib.base.DecimalInputVisualTransformation
import com.sychip.fhc.lib.base.FhcTopAppBar
import com.sychip.fhc.lib.base.ThousandSeparatorVisualTransformation
import com.sychip.fhc.lib.base.isDouble
import com.sychip.fhc.lib.composable.AnimatingFabContent
import kotlinx.coroutines.launch
import timber.log.Timber


@Composable
fun SettingsScreen(modifier: Modifier = Modifier,
                   onNavigationClick: () -> Unit ={},
                   viewModel: SettingsViewModel = hiltViewModel(),
                   snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }) {


    val  context = LocalContext.current
    val aaa = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) {
            uri->
        if(uri != null){

            Toast.makeText(context, uri.path, Toast.LENGTH_LONG).show()
            Timber.i("  >>>>>>>>>>>>>>>>>>>>>>>>> %s  ", uri)

        }
    }
    val coroutine = rememberCoroutineScope()
    val bottomSheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)

    val modalTypeState = remember { mutableIntStateOf(0) }
    val popupState = rememberUseCaseState(false)
    var isDrawPath by remember { mutableStateOf(false) }
    Scaffold(
        topBar = {
            FhcTopAppBar(
                title =  R.string.app_name,
                navigationIcon = {
                    IconButton(onClick = onNavigationClick) {
                        Icon(Icons.Filled.Menu, stringResource(id = R.string.open_drawer))
                    }
                },
                actions ={}
            )
        },
    ) { innerPadding ->
        val painter = rememberVectorPainter(image = Icons.AutoMirrored.Filled.BluetoothSearching)
        val modifier = Modifier
            .fillMaxSize()
            .padding(top = innerPadding.calculateTopPadding())
            // Consume this insets so that it's not applied again when using safeDrawing in the hierarchy below
        .consumeWindowInsets(innerPadding)
        Column( modifier) {
            Column(modifier = Modifier.wrapContentHeight().imePadding().verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally) {
                AnimatingFabContent(

                    icon = {
                        Icon(Icons.Filled.Add,contentDescription = null, modifier = Modifier.clickable {
                            isDrawPath = !isDrawPath
                        })
                    },
                    text = {
                        Text("A啊1")
                    }, modifier = Modifier.size(40.dp),
                    extended = isDrawPath
                )
//                MultiStateAnimationCircleFilledCanvas()
//                MultiStateAnimationCircleStrokeCanvas()
                    Box(modifier = Modifier.fillMaxWidth().aspectRatio(16f/9f).clipToBounds().background(Color.Gray)){
                        val painter = painterResource(id = R.mipmap.ic_launcher)
                        val zoomState = rememberZoomState(contentSize = painter.intrinsicSize)
                        Image(
                            painter = painter,
                            contentDescription = "Zoomable image",
                            contentScale = ContentScale.Fit,
                            modifier = Modifier
                                .fillMaxSize()
                                .zoomable(zoomState,
                                    onDoubleTap = { position ->
                                        val targetScale = when {
                                            zoomState.scale < 2f -> 2f
                                            zoomState.scale < 4f -> 4f
                                            else -> 1f
                                        }
                                        zoomState.changeScale(targetScale, position)
                                    }
                                ),
                        )
                    }
                val catImage = ImageBitmap.imageResource(id = R.drawable.murata_bike)

                Box(modifier = Modifier.fillMaxWidth().aspectRatio(16f/9f).clipToBounds().background(Color.Gray)){
                    val zoomState = rememberZoomState(contentSize = Size(catImage.width*1.0f, catImage.height*1.0f))

                    Canvas(
                        modifier = Modifier.fillMaxSize()
                            .zoomable(zoomState,
                                onDoubleTap = { position ->
                                    val targetScale = when {
                                        zoomState.scale < 2f -> 2f
                                        zoomState.scale < 4f -> 4f
                                        else -> 1f
                                    }
                                    zoomState.changeScale(targetScale, position)
                                },
                                onTap = {
                                    isDrawPath = !isDrawPath
                                }

                            )
//                            .pointerInteropFilter {
//                                when (it.action){
//                                    MotionEvent.ACTION_DOWN ->{
//
//                                    }
//                                    else -> {}
//                                }
//                                true
//                            }
                    ){
                        drawImage(image = catImage, topLeft = Offset(200f, 0f))
                        if(isDrawPath){
                            inset(100f,100f,100f,100f){
                                drawRect(color = Color.Red)
                            }
                        }
                    }
                }

//                    Column(modifier = Modifier.height(300.dp).background(Color.LightGray).fillMaxWidth()
////                    .layout { measurable, constraints ->
////                    // an example modifier that adds 50 pixels of vertical padding.
////                    val padding = 0
////                    val placeable = measurable.measure(constraints.offset(vertical = -padding))
////                    Timber.i("  >>>>>>>>>>>>>>>>>>>>>>>>> %s ", constraints)
////                    layout(placeable.width, placeable.height + padding) {
////                        placeable.placeRelative(0, padding)
////                    }
////                }
//                    ){
//
//                    }
                    KeyboardHandlingDemo2()
                    ElevatedButton(
                        onClick = {
                            aaa.launch(arrayOf("application/zip"))//,"image/jpeg","image/png","video/*"
                        }
                    ) {
                        Text(text = "File Picker")
                    }
                    ElevatedButton(
                        onClick = { popupState.show() }
                    ) {
                        Text(text = "Show CalendarView PopUp")
                    }


                    PopupSample(popupState)


                    ElevatedButton(
                        onClick = {
                            modalTypeState.intValue = 0
                            coroutine.launch {
                                bottomSheetState.show()
//                    state.animateTo(ModalBottomSheetValue.Expanded)
                            }
                        }) {
                        Text(text = "Show BottomSheet Canlendar")
                    }
                    ElevatedButton(
                        onClick = {
                            modalTypeState.intValue = 1
                            coroutine.launch {
                                bottomSheetState.show()
//                    state.animateTo(ModalBottomSheetValue.Expanded)
                            }
                        }) {
                        Text(text = "Show BottomSheet List")
                    }
//                SimpleBottomSheetScaffold()


            }

//            BottomSheetSample(
//                modalTypeState = modalTypeState,
//                bottomSheetState = bottomSheetState,
//                onSelectOption = {index, option ->
//                    Timber.i("  >>>>>>>>>>>>>>>>>>>>>>>>> %s  %s", index, option)
//                },
//                selectionCalendar = CalendarSelection.Dates(
//                    onSelectDates = { datas ->
//                        datas.forEach { item ->
//                            Timber.i("  >>>>>>>>>>>>>>>>>>>>>>>>> %s", item)
//                        }
//                        coroutine.launch { bottomSheetState.hide() }
//                    },
//                    onNegativeClick = {
////                coroutine.launch { state.hide()}
//                        Timber.i("  >>>>>>>>>>>>>>>>>>>>>>>>> onNegativeClick")
//                    },
//                    onExtraButtonClick = {
//                        Timber.i("  >>>>>>>>>>>>>>>>>>>>>>>>> onExtraButtonClick")
//                    },
//                )
//            ) {
//
//            }

//
//            Box {
//                Scaffold(
//                    snackbarHost = { SnackbarHost(snackbarHostState) },
//                    modifier = Modifier.fillMaxSize(),
//                    topBar = {
//
//                    },
//                    floatingActionButton = {
//                        FloatingActionButton(onClick = {
//
//                        }) {
//                            Icon(Icons.Filled.Refresh, stringResource(id = R.string.edit_task))
//                        }
//                    }
//                ) { paddingValues ->
//                    Column(
//                        modifier = Modifier
//                            .padding(paddingValues)
//                            .fillMaxSize()
//                            .fillMaxSize()
//                            .background(Color.White),
//                        // parameters set to place the items in center
//                        horizontalAlignment = Alignment.CenterHorizontally,
//                        verticalArrangement = Arrangement.Center
//                    ) {
//                        // Icon Composable
//                        Icon(
//                            imageVector = Icons.Default.Search,
//                            contentDescription = "search",
//                            tint = Color(0xFF0F9D58)
//                        )
//                        // Text to Display the current Screen
//                        Text(text = "Search", color = Color.Black)
//
//                        val testFlow by viewModel.testFlow.collectAsStateWithLifecycle(ScanningState.Loading)
//
//                        val pullRefreshState = rememberPullToRefreshState()
//                        val scope = rememberCoroutineScope()
//
//                        Column(modifier = Modifier.fillMaxSize()) {
//
//                            PullToRefreshBox(
//                                isRefreshing = testFlow is ScanningState.Loading,
//                                onRefresh = {
//                                    viewModel.reloadTestData()
//                                    scope.launch {
//                                        pullRefreshState.animateToHidden()
//                                    }
//                                },
//                                state = pullRefreshState,
//                                content = {
//                                    Aaa(viewModel, snackbarHostState)
////                    DevicesListView(
////                        isLocationRequiredAndDisabled = isLocationRequiredAndDisabled,
////                        state = state,
////                        modifier = Modifier.fillMaxSize(),
////                        onClick = { onResult(it) },
////                        deviceItem = deviceItem,
////                    )
//                                }
//                            )
//                        }
//                    }
//                }
//            }
        }
    }
}

@SuppressLint("TimberArgCount")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun Aaa(viewModel: SettingsViewModel, snackbarHostState: SnackbarHostState){
    val uiTestState: SettingsViewModel.UiTestState by viewModel.testFlow.collectAsStateWithLifecycle()
    val uiTestStateStr = remember { mutableStateOf("  -- ")}
    if(uiTestState is SettingsViewModel.UiTestState.Null) uiTestStateStr.value = "Null"
    else if(uiTestState is  SettingsViewModel.UiTestState.Loading) uiTestStateStr.value = "Loading"
    else if(uiTestState is  SettingsViewModel.UiTestState.Success) uiTestStateStr.value = "Success:  "+(uiTestState as SettingsViewModel.UiTestState.Success).data.size
    else if(uiTestState is  SettingsViewModel.UiTestState.Error)  uiTestStateStr.value = "Error" + (uiTestState as SettingsViewModel.UiTestState.Error).throwable?.message



    val sliderPosition = remember { mutableFloatStateOf(0f) }

    val uiTest = remember { mutableStateOf("LoadTestData") }
    Column {
//    val context = LocalContext.current
    Button(
        onClick = {
//            Toast.makeText(context, "Welcome to Geeks for Geeks", Toast.LENGTH_LONG).show()
            if(uiTestState ==  SettingsViewModel.UiTestState.Null) viewModel.loadTestData()
            else viewModel.reloadTestData()
        },
        modifier = Modifier.padding(16.dp),
        enabled = true,
        shape = RoundedCornerShape(12.dp),
        colors = ButtonDefaults.buttonColors( contentColor = Color.White, containerColor = Color.Green),
        elevation = ButtonDefaults.buttonElevation(defaultElevation = 10.dp),
        border = BorderStroke(width = 2.dp, brush = SolidColor(Color.Blue)),
        contentPadding = PaddingValues(start = 20.dp, top = 12.dp, end = 20.dp, bottom = 12.dp),
        interactionSource = remember { MutableInteractionSource() }
    ) {
//        if(uiTestState != UiTestState.Null) {
//            CircularProgressAnimated()
//        }
        Text(
            text = uiTest.value,
            fontSize = 16.sp,
            fontWeight = FontWeight.Bold,
            fontStyle = FontStyle.Italic,
            fontFamily = FontFamily.Serif
        )
    }



    Text(
        modifier = Modifier
            .fillMaxWidth()
            .height(20.dp),
        text = uiTestStateStr.value ,
        textAlign = TextAlign.Center,
        fontSize = 14.sp,
        style = MaterialTheme.typography.titleLarge
    )
    when (uiTestState) {
        SettingsViewModel.UiTestState.Null -> {
            uiTestStateStr.value = "Null"
        }
        is SettingsViewModel.UiTestState.Loading -> {
            uiTestStateStr.value = "Loading"
        }
        is SettingsViewModel.UiTestState.Success -> {
            uiTestStateStr.value = "Success:  "+(uiTestState as SettingsViewModel.UiTestState.Success).data.size
        }
        is SettingsViewModel.UiTestState.Error -> {
            uiTest.value = "ReloadTestData"
            uiTestStateStr.value = "Error" + (uiTestState as SettingsViewModel.UiTestState.Error).throwable?.message
        }
    }

//    OutlinedTextField(
//        value = alertState.title,
//        onValueChange = {str->
//
//            Timber.i("    >>>>>>>>>>>>>>>>>>>>>>>>>   StartViewModel  init   >>>>>>>>>>>>>>>>>>>>>>>>> %s", str)
//        },
//        label = { Text(text = "label") },
//        modifier = Modifier,
//        shape = RoundedCornerShape(4.dp),
//    )
//




    val scope = rememberCoroutineScope()
    Column(modifier = Modifier
        .padding(horizontal = 16.dp)
        .height(100.dp)) {
        Slider(
            modifier = Modifier,
            value = sliderPosition.floatValue,
            onValueChange = { sliderPosition.floatValue = it },
            valueRange = 0f..100f,
            onValueChangeFinished = {

                Timber.i("onValueChangeFinished   %s", sliderPosition.floatValue)
                // launch some business logic update with the state you hold
                // viewModel.updateSelectedSliderValue(sliderPosition)

                showSnackbar(scope,
                    snackbarHostState = snackbarHostState,
                    message = "Snackbar Snackbar Snackbar Snackbar                              Snackbar # "+ sliderPosition.floatValue,
                    actionLabel =  "Action",
                    onDismissed = {
                        Timber.d("SnackbarDemo    Dismissed")
                    }, onActionPerformed = {
                        Timber.d("SnackbarDemo    Snackbar button clicked")
                    }
                )

            },
            // Only allow multiples of 10. Excluding the endpoints of `valueRange`,
            // there are 9 steps (10, 20, ..., 90).
//        steps = 9,
        )
    }
    }
}
@Preview
@Composable
fun KeyboardHandlingDemo2() {
Column(modifier = Modifier.fillMaxWidth().wrapContentHeight()) {
    val interactionSource = remember { MutableInteractionSource() }
    var tfvState by remember { mutableStateOf(
        TextFieldValue(
            text ="",
            selection = TextRange(0)
        )
    ) }
    val decimalFormatter = DecimalFormatter()
    OutlinedTextField(
        modifier = Modifier
            .fillMaxWidth()
            .padding(top = 16.dp, start = 10.dp, end = 10.dp)
            .onGloballyPositioned { layoutCoordinates ->
//            val position = layoutCoordinates.positionInRoot()
//            val textFieldWidth = layoutCoordinates.size.width
//            val cursorX = text.length.takeIf { it == 0 }?.let{ 0}?:{position.x + textFieldWidth / text.length * cursorPos}

            },
        value = tfvState,
        onValueChange = {it->
            val rlt = decimalFormatter.cleanup(it.text, tfvState.selection.start,min=-10.0,max = 88.0,isInt = true)
            Timber.i("onValueChangeFinished   it:%s   text:%s     val:%s    pos:%s   selection:%s", tfvState.text, tfvState.text, rlt.second, rlt.first, tfvState.selection)
            tfvState = TextFieldValue(
                text =rlt.second,
                selection = TextRange(rlt.first)
            )
        },
        singleLine = true,
        interactionSource = interactionSource,
        enabled = true,
        keyboardOptions = KeyboardOptions(
            autoCorrectEnabled = true,
            keyboardType = KeyboardType.Decimal,
        ),
        visualTransformation = DecimalInputVisualTransformation(decimalFormatter)
    )
    Text(
        modifier = Modifier
            .fillMaxWidth()
            .padding(top = 16.dp, start = 10.dp, end = 10.dp),
        text = "This is a very long text that will not fit in a single line",
        maxLines = 1,
        fontSize = 24.sp,
        overflow = TextOverflow.Ellipsis
    )

    val focusManager = LocalFocusManager.current
    val kc = LocalSoftwareKeyboardController.current
    val coroutineScope = rememberCoroutineScope()
    val label = remember {
        mutableStateListOf("1-isDigit", "maxlength 10", "3", "4", "5", "6", "7", "8", "9", "10","11", "12", "13", "14", "15")
    }
    val states = remember {
        mutableStateListOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10","11", "12", "13", "14", "15")
    }
    val listState = rememberLazyListState()
    var isError by remember { mutableStateOf(states[0].length < 20) }
    var amount by remember { mutableStateOf("123456") }
    OutlinedTextField(
        value = amount,
        onValueChange = {
            amount = it
            isError = amount.length >5
        },
        isError = isError,
        colors = OutlinedTextFieldDefaults.colors (
            errorSupportingTextColor =  Color.Red,
            errorContainerColor = Color.Red.copy(alpha = 0.01f),
            errorLabelColor  =  Color.Red.copy(alpha = 0.8f)
        ),
        supportingText = {
            if (isError) {
                Text("Username should be at least 5 characters long")
            } else {
                null
            }
        },
        modifier = Modifier.onFocusChanged {it
//            isError = amount.length >5
            Timber.i("    onFocusChanged 1111>>>>>>>>>>>>>>>>>>>>>>>>> %s", it.isFocused)
            if(!it.isFocused){
                amount = "89765432"
            }
        },
        keyboardOptions = KeyboardOptions(
            keyboardType = KeyboardType.Number
        ),
        visualTransformation = ThousandSeparatorVisualTransformation()
    )

    LazyColumn(
        state = listState,
        modifier = Modifier
            .fillMaxWidth().height(400.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        itemsIndexed(states) { i, _ ->
            OutlinedTextField(
                label = {
                    Text(label[i])
                },

                value = states[i],
                placeholder = {Text(states[i])},
                singleLine = true,
                isError = isError,
                colors = OutlinedTextFieldDefaults.colors (
                    errorSupportingTextColor =  Color.Red,
                    errorContainerColor = Color.Red.copy(alpha = 0.01f),
                    errorLabelColor  =  Color.Red.copy(alpha = 0.8f)
                ),
                supportingText = {
                    if (isError) {
                        Text("Username should be at least 5 characters long")
                    } else {
                        null
                    }
                },
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(top = 16.dp, start = 10.dp, end = 10.dp),
                keyboardOptions =
                if(i==0){
                    KeyboardOptions(imeAction = ImeAction.Done,keyboardType = KeyboardType.Decimal)
                }else if(i==states.size-1){
                    KeyboardOptions(imeAction = ImeAction.Done,keyboardType = KeyboardType.Number)
                }else {
                    KeyboardOptions(imeAction = ImeAction.Next)
                },
                keyboardActions =
                if(i==states.size-1){
                    KeyboardActions(
                        onDone = {
                            kc?.hide()
                        }
                    )
                }else {
                    KeyboardActions(
                        onNext = {
                            focusManager.moveFocus(FocusDirection.Down)

                            coroutineScope.launch {
                                listState.animateScrollToItem(i)
                            }
                        }
                    )
                },
                onValueChange = {
                    if (i==0){
//                        if (it.all { char -> char.isDigit() || char == '-'  || char == '.' }) {
//                            states[i] = it
//                        }
                        if (it.startsWith(".") || it.endsWith(".") ||  it.isDouble()) {
                            states[i] = it
                        }else{
                            val aa = states[i].toString()
                            states[i] = ""
                            states[i] = aa
                        }
                    }else if (i==1){
                        if (it.length <= 10) {
                            states[i] = it
                        }
                    }else{
                        states[i] = it
                    }

//                    if (it.length <= 10 && !it.contains(Regex("[qwerty123]"))){
//
//                        states[i] = it
//                    }
//                    if (android.util.Patterns.PHONE.matcher(it).matches()) {
//                        states[i] = it
//                    }

                    isError = states[i].length < 5
                },

                leadingIcon = {
                    if(i== 0){
                        IconButton(onClick = {
                            states[i] = states[i] + "+" + states[i]
                        }){
                            Icon(imageVector = Icons.Filled.Add,contentDescription = null, tint = if(isError){Color.Red}else{Color.Black})
                        }
                    }else{
                        null
                    }
                },
                trailingIcon = {
                    if(i== 0){
                        IconButton(onClick = {
                            states[i] = states[i] + "-" + states[i]
                        }){
                            Icon(imageVector = Icons.Filled.Remove,contentDescription = null, tint = if(isError){Color.Red}else{Color.Black})
                        }
                    }else{
                        null
                    }
                },

                )

        }
    }
}
}

